package com.coolw.common.exception;

/**
 * 业务异常类
 *
 * @author coolw
 * @date 2024/4/15 15:19
 */
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 4404945527762497742L;

    private String code;

    private String message;

    public BusinessException(String message) {
        this(null, message);
    }

    public BusinessException(String code, String message) {
        super("[" + code + "]" + message);
        this.code = code;
        this.message = message;
    }

    public BusinessException(String message, Throwable e) {
        this(null, message, e);
    }

    public BusinessException(String code, String message, Throwable e) {
        super("[" + code + "]" + message, e);
        this.message = message;
    }

    public BusinessException(ErrorCode errorCode) {
        this(errorCode.getCode(), errorCode.getMessage());
    }

    public BusinessException(ErrorCode errorCode, Throwable e) {
        this(errorCode.getCode(), errorCode.getMessage(), e);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
